<?php

/**
 * ExchangeController
 * 
 * @author
 * @version 
 */

require_once 'Zend/Controller/Action.php';

class ExchangeController extends Zend_Controller_Action {
	protected $_exchangeModel;
	
	public function init() {
		$this->_exchangeModel = new Eleven_Model_Exchange ( );
		
		$this->view->postForm = $this->getPostForm();
		
	}
	/**
	 * The default action - show the home page
	 */
	public function indexAction() {
		$exchanges = $this->_exchangeModel->getExchangeContents ( $this->_getParam ( 'page', 1 ), array ('publishdate DESC' ) );
		
		$this->view->assign(array('exchanges'=>$exchanges));
	}
	
	public function viewAction()
	{
		$exchange = $this->_exchangeModel
				->getExchangeContentById($this->_getParam('exchangeId'));
        
        if (null === $exchange) {
            throw new CMS_Exception_404('未知的文档， Exchange文档Id为 ' . $this->_getParam('id'));
        }
        
        $this->view->assign(array(
            'exchange' => $exchange,
            )
        );
	}
	
	public function publishAction()
	{
		
	}
	
	public function getPostForm()
	{
		$urlHelper = $this->_helper->getHelper('url');

        $this->_forms['post'] = $this->_exchangeModel->getForm('exchangePost');
        $this->_forms['post']->setAction($urlHelper->url(array(
            'controller' => 'customer' ,
            'action' => 'save'
            ),
            'default'
        ));
        
        $this->_forms['post']->setMethod('post');

        return $this->_forms['post'];
	}

}

